package com.Tencent.interview;

import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

/**
 * @author ZhangyiA
 * @describe: easy
 * @date 2021/07/03
 */

public class One_QueueOperation {
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        int T = input.nextInt();
        while(T -- > 0){
            int n = input.nextInt();
            Queue<Integer> que = new LinkedList<>();
            for(int i = 0 ; i < n ; i ++){
                String str = input.next();
                if(str.equals("PUSH")){
                    int val = input.nextInt();
                    que.offer(val);
                } else if(str.equals("TOP")){
                    if(que.isEmpty()) {
                        System.out.println(-1);
                    }
                    System.out.println(que.peek());
                } else if(str.equals("POP")){
                    if(que.isEmpty()) {
                        System.out.println(-1);
                    }
                    que.poll();
                } else if(str.equals("CLEAR")){
                    while(!que.isEmpty()){
                        que.poll();
                    }
                } else if(str.equals("SIZE")){
                    System.out.println(que.size());
                }
            }
        }
    }
}
/*
2
7
PUSH 1
PUSH 2
TOP
POP
TOP
POP
POP
5
PUSH 1
PUSH 2
SIZE
POP
SIZE
* */